/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgGlobal
    {
        private readonly Dictionary<int, CfgGlobal> _dataMap;
        private readonly List<CfgGlobal> _dataList;

        /// <summary>
        /// 关卡电梯运行时长（毫秒）
        /// </summary>
        public int Level_ElevatorDuration { get; private set; }
        /// <summary>
        /// 实体恢复之前旋转的延迟（毫秒）
        /// </summary>
        public int Level_RotRestoreDelay { get; private set; }
        /// <summary>
        /// 主角的灵魂id
        /// </summary>
        public int RoleSoulId { get; private set; }
        /// <summary>
        /// 最大编队数量
        /// </summary>
        public int FormMaxCount { get; private set; }
        /// <summary>
        /// 编队正式成员数量
        /// </summary>
        public int FormRegularHeroCount { get; private set; }
        /// <summary>
        /// 编队替补成员数
        /// </summary>
        public int FormBenchHeroCount { get; private set; }
        /// <summary>
        /// 编队替补成员开始位置
        /// </summary>
        public int FormBenchHeroStartPos { get; private set; }
        /// <summary>
        /// 编队名最大长度
        /// </summary>
        public int FormNameMaxLen { get; private set; }
        /// <summary>
        /// 英雄升级道具|单个道具提供经验
        /// </summary>
        public IReadOnlyList<int> HeroUpLvCostItems { get; private set; }
        /// <summary>
        /// 每获得1点经验消耗道具ID（金币）|每获得1点经验消耗道具数量
        /// </summary>
        public IReadOnlyList<int> HeroUpLvCostMoney { get; private set; }
        /// <summary>
        /// 当前版本英雄最大觉醒等级
        /// </summary>
        public int MaxHeroAwakenLv { get; private set; }
        /// <summary>
        /// 收集道具任务
        /// </summary>
        public int CollectItemQuest { get; private set; }
        /// <summary>
        /// 装备升级道具|单个道具提供经验
        /// </summary>
        public IReadOnlyList<int> EquipUpLvCostItems { get; private set; }
        /// <summary>
        /// 装备每获得1点经验消耗道具ID（金币）|每获得1点经验消耗道具数量
        /// </summary>
        public IReadOnlyList<int> EquipUpLvCostMoney { get; private set; }
        /// <summary>
        /// 英雄装备栏位上限
        /// </summary>
        public int MaxHeroEquipColumn { get; private set; }
        /// <summary>
        /// 英雄装备栏位解锁等级
        /// </summary>
        public IReadOnlyList<int> LimitLvUnlockHeroEquipColumns { get; private set; }
        /// <summary>
        /// 英雄宠物栏位解锁等级
        /// </summary>
        public int LimitLvUnlockHeroPetColumn { get; private set; }
        /// <summary>
        /// 宠物经验道具ID
        /// </summary>
        public int PetExpItemCid { get; private set; }
        /// <summary>
        /// 解锁宠物技能槽需求 道具ID|数量
        /// </summary>
        public IReadOnlyList<int> PetUnlockAttributeSlotCost { get; private set; }
        /// <summary>
        /// 宠物名字最大长度
        /// </summary>
        public int PetNameMaxLen { get; private set; }
        /// <summary>
        /// 主城地区列表
        /// </summary>
        public IReadOnlyList<int> MainCityRegions { get; private set; }

        public TbCfgGlobal(ByteBuf _buf)
        {
            //first read common data
            _TbCommonGlobal _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonGlobal(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgGlobal>(size * 3 / 2);
            _dataList = new List<CfgGlobal>(size);

            for (int i = 0; i < size; i++)
            {
                CfgGlobal _v;
                _v = CfgGlobal.DeserializeCfgGlobal(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 
            Level_ElevatorDuration = _buf.ReadInt();
            Level_RotRestoreDelay = _buf.ReadInt();
            RoleSoulId = _buf.ReadInt();
            FormMaxCount = _buf.ReadInt();
            FormRegularHeroCount = _buf.ReadInt();
            FormBenchHeroCount = _buf.ReadInt();
            FormBenchHeroStartPos = _buf.ReadInt();
            FormNameMaxLen = _buf.ReadInt();
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0]; HeroUpLvCostItems = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int __v0; __v0 = _buf.ReadInt(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0]; HeroUpLvCostMoney = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int __v0; __v0 = _buf.ReadInt(); __f0[__i0] = __v0;} }
            MaxHeroAwakenLv = _buf.ReadInt();
            CollectItemQuest = _buf.ReadInt();
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0]; EquipUpLvCostItems = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int __v0; __v0 = _buf.ReadInt(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0]; EquipUpLvCostMoney = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int __v0; __v0 = _buf.ReadInt(); __f0[__i0] = __v0;} }
            MaxHeroEquipColumn = _buf.ReadInt();
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0]; LimitLvUnlockHeroEquipColumns = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int __v0; __v0 = _buf.ReadInt(); __f0[__i0] = __v0;} }
            LimitLvUnlockHeroPetColumn = _buf.ReadInt();
            PetExpItemCid = _buf.ReadInt();
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0]; PetUnlockAttributeSlotCost = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int __v0; __v0 = _buf.ReadInt(); __f0[__i0] = __v0;} }
            PetNameMaxLen = _buf.ReadInt();
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0]; MainCityRegions = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int __v0; __v0 = _buf.ReadInt(); __f0[__i0] = __v0;} }

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgGlobal> DataMap => _dataMap;
        public IReadOnlyList<CfgGlobal> DataList => _dataList;

        public CfgGlobal Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgGlobal] config not found,id:" + key.ToString());

            return null;
        }

        public CfgGlobal GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "global";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgGlobal LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgGlobal(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgGlobal
    {
        private CfgGlobal(ByteBuf _buf, _TbCommonGlobal _commonData)
        {
            Id = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; Data = _commonData._field0[dataIndex]; }

            PostInit();
        }

        internal static CfgGlobal DeserializeCfgGlobal(ByteBuf _buf, _TbCommonGlobal _commonData)
        {
            return new CfgGlobal(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 数据
        /// </summary>
        public string Data { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonGlobal
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal _TbCommonGlobal(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
        }

    }
}
